
#********************************* LICENSE ************************************
#
# Copyright 2011 Alessandro Carrega
# email: alessandro.carrega@unige.it
#
# This file is part of google_code_jam_2011.
#
# google_code_jam_2011 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# google_code_jam_2011 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with google_code_jam_2011.  If not, see <http://www.gnu.org/licenses/>.
#
#******************************** LICENSE ************************************/

CONFIG = Release
DIR= $(shell pwd) 

CXX= g++
CXXFLAGS += -Wall -pg -Wextra -I$(DIR) \
	-pedantic -Wmain -Wswitch-default -Wswitch-enum -Wmissing-include-dirs \
	-Wmissing-declarations -Winline -Wfloat-equal -Wundef -Wcast-align -Wredundant-decls -Winit-self \
	-Woverloaded-virtual 
LDFLAGS += 

ifeq ($(CONFIG),Release)
	CXXFLAGS +=
	LDFLAGS += -O3 -static	
else
	CXXFLAGS += -g
	LDFLAGS += 
endif

SOURCES_GAME_1 = game_1.cpp
SOURCES_GAME_2 = game_2.cpp
EXECUTABLE = game_1 game_2

OBJS_GAME_1 = $(addprefix $(CONFIG)/,$(SOURCES_GAME_1:.cpp=.o))
OBJS_GAME_2 = $(addprefix $(CONFIG)/,$(SOURCES_GAME_2:.cpp=.o))

MAKE = make
RM = rm -f
RM_DIR = rm -rf
MK_DIR = mkdir

all: $(EXECUTABLE)
	
game_1: $(SOURCES_GAME_1) $(OBJS_GAME_1) Makefile create_dir 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJS_GAME_1) -o $(CONFIG)/$@
	
game_2: $(SOURCES_GAME_2) $(OBJS_GAME_2) Makefile create_dir 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJS_GAME_2) -o $(CONFIG)/$@

$(CONFIG)/%.o: %.cpp Makefile create_dir
	$(CXX) $(CXXFLAGS) -c $< -o $@
	
create_dir:
	$(shell [ ! -d  $(CONFIG) ] && $(MK_DIR) $(CONFIG))

clean:
	$(RM) $(CONFIG)/*
	$(shell [ -d $(CONFIG) ] && $(RM_DIR) $(CONFIG))
	
rebuild: clean $(EXECUTABLE)

license:
	@cat LICENSE.txt
	
readme:
	@cat README.txt
	
depend:	$(SOURCES)
	makedepend -m -I../ -Y *.cpp $^

# DO NOT DELETE THIS LINE -- make depend needs it
